/*
 * Copyright (c) 2020 Fraunhofer FOKUS and others. All rights reserved.
 *
 * See the NOTICE file(s) distributed with this work for additional
 * information regarding copyright ownership.
 *
 * This program and the accompanying materials are made available under the
 * terms of the Eclipse Public License 2.0 which is available at
 * http://www.eclipse.org/legal/epl-2.0
 *
 * SPDX-License-Identifier: EPL-2.0
 *
 * Contact: mosaic@fokus.fraunhofer.de
 */
package org.eclipse.mosaic.interactions.mapping;

import org.apache.commons.lang3.builder.EqualsBuilder;
import org.apache.commons.lang3.builder.HashCodeBuilder;
import org.apache.commons.lang3.builder.ToStringBuilder;
import org.eclipse.mosaic.lib.geo.GeoPoint;
import org.eclipse.mosaic.lib.objects.mapping.MecMapping;
import org.eclipse.mosaic.rti.api.Interaction;

import java.util.List;

import static org.apache.commons.lang3.builder.ToStringStyle.SHORT_PREFIX_STYLE;

/**
 * This extension of {@link Interaction} informs about a new Multi-Access Edge Computing(MEC) added to the simulation
 */
public class MecRegistration extends Interaction {

    private static final long serialVersionUID = 1;

    public static final String TYPE_ID = createTypeIdentifier(MecRegistration.class);

    private final MecMapping mecMapping;

    /**
     * Creates a new interaction that inform about a recently added MEC in the simulation
     *
     * @param time            Timestamp of this interaction, unit: [ns]
     * @param name            Mec identifier
     * @param group           Mec group identifier
     * @param applications    List of applications the MEC is equipped with
     * @param position        Mec position
     * @param radius          Mec seeing distance
     * @param heading         Mec heading, unit: [degree]
     * @param angle           Mec seeing angel, unit: [degree]
     */
    public MecRegistration(final long time, final String name, final String group,
                           final List<String> applications, final String extName, final GeoPoint position, final double radius,
                           final double heading, final double angle, final boolean enableShow) {

        super(time);
        this.mecMapping = new MecMapping(name, group, applications, extName, position, radius, heading, angle, enableShow);
    }

    public MecMapping getMecMapping() {
        return mecMapping;
    }

    @Override
    public int hashCode() {
        return new HashCodeBuilder(7, 59)
                .append(mecMapping)
                .toHashCode();
    }

    @Override
    public boolean equals(Object obj) {
        if (obj == null) {
            return false;
        }
        if (obj == this) {
            return true;
        }
        if (obj.getClass() != getClass()) {
            return false;
        }

        MecRegistration other = (MecRegistration) obj;
        return new EqualsBuilder()
                .append(this.mecMapping, other.mecMapping)
                .isEquals();
    }

    @Override
    public String toString() {
        return new ToStringBuilder(this, SHORT_PREFIX_STYLE)
                .appendSuper(super.toString())
                .append("mecMapping", mecMapping)
                .toString();
    }
}
